<?php
class Cpu
{
    public function powerUp()
    {
        echo "CPU加电\r\n";
        return true;
    }
}

interface HardDisk
{
    public function powerUp();
}
class Ssd implements HardDisk
{
    public function powerUp()
    {
        echo "硬盘加电\r\n";
        return true;
    }
}

interface Os
{
    public function init();
}
class Windows implements Os
{
    public function init()
    {
        echo "系统引导完成\r\n";
        return true;
    }
    public function greet()
    {
        echo "欢迎\r\n";
        return true;
    }
    public function quit()
    {
        return true;
    }
}

/**
 * 外观模式可以隐藏系统内部的复杂细节，为使用者提供一个简洁的外观
 */
class Computer
{
    /** @var Cpu $cpu */
    protected $cpu=null;
    /** @var HardDisk $hd */
    protected $hd=null;
    /** @var Os $os */
    protected $os=null;
    public function __construct()
    {
        $this->cpu=new Cpu;
        $this->hd=new Ssd;
        $this->os=new Windows;
    }
    protected function test()
    {
        echo "开机自检完成\r\n";
        return true;
    }
    public function open()
    {
        $this->cpu->powerUp();
        $this->hd->powerUp();
        $this->test();
        $this->os->init();
        return $this->os;
    }
    public function close()
    {
        return true;
    }
}

header('Content-Type: text/plain');
$computer=new Computer;
$os=$computer->open();
$os->greet();
